Repository navigation
Benchmarks: the one-row terminals of a mapped reader, the shape before the First/Single dedupe - #291
Merged
Merged
Conversation
…e the First/Single dedupe A BenchmarkDotNet class family (`OneRowInt`, `OneRowClass`) for the cost of one call of `First`, `FirstOrDefault`, `Single` and `SingleOrDefault`, synchronous and asynchronous, over an in-memory `DataTableReader` (no database): a lookup by key is the typical use, so the fixed cost of one call is what matters, in time and in allocated bytes. Each runs on a table of one row; `First` and `FirstOrDefault` also on a table of 100 rows, where the terminal must stop after the first. A hand-written read of the one row through the same selector delegate is the baseline of each group (synchronous and asynchronous), and a hand-written `Single` (the row, then a second read to check there is no more) is its like-for-like; every async variant has the same shape (one async method that creates, uses and disposes its reader), every variant returns its row so the harness consumes it, and the memory diagnoser is on. This is the BEFORE shape: the change that would put the `First` and `Single` bodies onto the `FirstOrDefault` and `SingleOrDefault` ones (one private helper, as the dead-code review proposed) is measured against it. `--verify-onerow` checks, without BenchmarkDotNet, that every variant gives the row of the hand-written read, twice each. Not run as timed benchmarks by this change: that needs a quiet machine. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A BenchmarkDotNet class family for the one-row terminals, so the planned
First/Singlechange (put their bodies onto theFirstOrDefault/SingleOrDefaultones with one private helper, K-F of the dead-code review) can be measured against the shape they have now. Build-only here: nothing was run as a timed benchmark (that needs a quiet machine), and no BenchmarkDotNet run was made.What it measures
OneRowIntandOneRowClass(a class with a string), each over an in-memoryDataTableReader(no database): the fixed cost of one call, in time and allocated bytes, since a lookup by key is the typical use.Single: the row, then a second read to check there is no more (the like-for-like ofSingle)First,FirstOrDefaultSingle,SingleOrDefaultResults are grouped sync and async, each group against its own baseline. Every async variant has the same shape (one async method that creates, uses and disposes its own reader, returning
ValueTask), so the library's calls and the hand-written ones carry the same machinery; every variant returns its row, so the harness consumes it; the memory diagnoser is on. Filters:*OneRowInt*,*OneRowClass*, and within them*Sync_*or*Async_*.--verify-onerow(no BenchmarkDotNet, nothing measured) checks that every variant gives the row of the hand-written read, twice each, for both row kinds: "one-row variants: all equal".Checks
dotnet format styleandanalyzersat--severity inforeport nothing on all 14 projects; the docs build is clean (a benchmark-only change, run through the whole gate anyway).Single's second read, so a hand-writtenSinglewas added; the group rule is also on the concrete classes. Not taken: theOneRowChecksexception handling (a throwing variant aborts the check, which is loud enough).🤖 Generated with Claude Code